package leetcode1;

import java.util.Arrays;

public class Day17 {
    public static void main(String[] args) {

    }
    public int eraseOverlapIntervals(int[][] intervals) {
        //1.按左端点排序
        Arrays.sort(intervals,(a, b)->{
            return a[0] - b[0];
        });
        //2.记录重叠区间
        int ret=0;
        int right = intervals[0][1];
        for(int i=1;i<intervals.length;i++) {
            int a = intervals[i][0];
            int b = intervals[i][1];
            if(a < right) {
                //有重叠区域
                ret++;
                right=Math.min(right,b);
            }else {
                right=b;
            }
        }
        return ret;
    }
}
